define-record and srfi-17

Regular define-record records don't support generalized set. This macro implements support for binding to srfi-17.

(define-syntax define-gs-record
  (er-macro-transformer
   (lambda (x r c)
     (let ((type (cadr x))
           (fields (cddr x))
           (%begin (r 'begin))
           (%define-record (r 'define-record))
           (%define (r 'define))
           (%getter-with-setter (r 'getter-with-setter)))
       `(,%begin
         (,%define-record ,type ,@fields)
         ,@(map (lambda (f)
                  (let* ((getter (symbol-append
                                  (strip-syntax type)
                                  '-
                                  (strip-syntax f)))
                         (setter (symbol-append
                                  (strip-syntax getter)
                                  '-set!)))
                    (list %define
                          getter
                          (list %getter-with-setter getter setter))))
                fields))))))

now you can say

(define-gs-record test a b c)

(define t (make-test 1 2 3))
(set! (test-a t) 'new-val)